<template>
	<view class="list-page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<!--  refresher-only @onRefresh="onRefresh" -->
		<pageTxt>
			<listTabCom class="listTabCom" :tabList="topTabListArr" @topTabClick="topTabClick" :current="topTabIndex"></listTabCom>
			<!-- 施工管理 -->
			<constructionManagement ref="constructionManagement" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 1"></constructionManagement>
			<!-- 施工日志 -->
			<constructionLog ref="constructionLog" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 2"></constructionLog>
			<!-- 质量验收 -->
			<qualityAcceptance ref="qualityAcceptance" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 3"></qualityAcceptance>
			<!-- 工程整改 -->
			<engineeringRectification ref="engineeringRectification" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 4"></engineeringRectification>
			<!-- 售后管理 -->
			<afterSalesManagement ref="as" :option="{}" :conentHeight="conentHeight" v-if="showIndex == 5"></afterSalesManagement>
		</pageTxt>
	</view>
</template>

<script>
import constructionManagement from './components/constructionManagement/constructionManagement.vue';
import constructionLog from './components/constructionLog/constructionLog.vue';
import qualityAcceptance from './components/qualityAcceptance/qualityAcceptance.vue';
import engineeringRectification from './components/engineeringRectification/engineeringRectification.vue';
import afterSalesManagement from './components/afterSalesManagement/afterSalesManagement.vue';
export default {
	components: {
		constructionManagement,
		constructionLog,
		qualityAcceptance,
		engineeringRectification,
		afterSalesManagement
	},
	data() {
		return {
			searchShow: false,
			loading: true,
			dataList: [],
			searchData: {
				keyword: ''
			},
			conentHeight: 0,
			topTabIndex: '-1',
			showIndex: 0,
			topTabList: [
				{
					name: '施工管理',
					menu: '/sggl',
					key: 1
				},
				{
					name: '施工日志',
					menu: '/sgrz',
					key: 2
				},
				{
					name: '质量验收',
					menu: '/zlys',
					key: 3
				},
				{
					name: '工程整改',
					menu: '/gczgd',
					key: 4
				},
				{
					name: '售后管理',
					menu: '/shgl',
					key: 5
				}
			],
			topTabListArr: []
		};
	},
	onShow() {
		// 请求更新某条数据
		this.$nextTick(() => {
			switch (Number(this.showIndex)) {
				case 1:
					if (!this.$refs.constructionManagement) return;
					this.$refs.constructionManagement.refreshItemFunc();
					break;
				case 2:
					break;
				case 3:
					if (!this.$refs.qualityAcceptance) return;
					this.$refs.qualityAcceptance.refreshItemFunc();
					break;
				case 4:
					if (!this.$refs.engineeringRectification) return;
					this.$refs.engineeringRectification.refreshItemFunc();
					break;
				case 5:
					if (!this.$refs.as) return;
					this.$refs.as.updateListIdx();
					break;
			}
		});
	},
	onLoad(option) {
		this.getHeight();
		// 菜单权限判断
		let topTabListArr = [];
		this.topTabList.forEach((item) => {
			if (this.$menuShow(item.menu)) {
				topTabListArr.push(item);
			}
		});
		this.topTabListArr = topTabListArr;

		if (option.tabIndex) {
			let index = topTabListArr.findIndex((item) => {
				return item.key == option.tabIndex;
			});
			this.topTabIndex = index;
			this.showIndex = option.tabIndex;
		}
		// 页面参数处理
		this.$nextTick(() => {
			if (option.project_name) {
				switch (Number(this.showIndex)) {
					case 1:
						break;
					case 2:
						break;
					case 3:
						if (!this.$refs.qualityAcceptance) return;
						this.$refs.qualityAcceptance._data.searchForm.project_name = option.project_name;
						this.$refs.qualityAcceptance.searchFunc();
						break;
					case 4:
						if (!this.$refs.engineeringRectification) return;
						this.$refs.engineeringRectification._data.searchForm.project_name = option.project_name;
						this.$refs.engineeringRectification._data.searchForm.rectification_status = option.rectification_status || '';
						this.$refs.engineeringRectification.searchFunc();
						break;
					case 5:
						if (!this.$refs.as) return;
						this.$refs.as._data.searchForm.project_name = option.project_name;
						this.$refs.as._data.searchForm.after_status = option.after_status || '';
						this.$refs.as.searchFunc();
						break;
					default:
				}
			}
		});
	},
	methods: {
		getHeight() {
			// 创建节点查询
			let that = this;
			const systemInfo = uni.getSystemInfoSync();
			const query = uni.createSelectorQuery().in(that);
			query.select('.listTabCom').boundingClientRect();
			query.exec((res) => {
				that.conentHeight = systemInfo.screenHeight - (res[0].height + 20); //组件可用高度 20状态栏高度（动态获取高度不包含状态栏高度）
				setTimeout(() => {
					that.loading = false;
				}, 200);
			});
		},
		topTabClick(index) {
			this.topTabIndex = index;
			this.showIndex = this.topTabListArr[index].key;
		}
	}
};
</script>

<style lang="scss" scoped>
@import 'engineeringManagement.scss';
</style>
